package com.ll.customException;

import java.util.Scanner;

/**
 * @author 刘龙
 * @version 1.0
 */
public class Homework01 {
    public static void main(String[] args) throws Exception{
        try {
            if (args.length != 2) {
                throw new ArrayIndexOutOfBoundsException("参数个数不对");
            }

            int n1 = Integer.parseInt(args[0]);
            int n2 = Integer.parseInt(args[1]);

            // 可能抛出算数异常
            double res = cal(n1, n2);

            System.out.println("result: " + res);
        } catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
        } catch (NumberFormatException e) {
            System.out.println("参数的格式不正确");
        } catch (ArithmeticException e) {
            System.out.println("算数异常");
            e.printStackTrace();
        }
    }

    public static double cal(int n1, int n2){
        return n1 / n2;
    }
}
